/*
 *说明：用户信息表 首页脚本
 *
 *@author liuxun 2012-03-06
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'身份证号',field:'org_code',align:'center',width:80},
            
            {title:'姓名',field:'org_name',align:'center',width:40},
            
            {title:'手机号',field:'mobile',align:'center',width:60},

            {title:'应发奖金',field:'remaining_bonus',align:'center',width:50},

            {title:'奖金总数',field:'totle_bonus',align:'center',width:50},

            {title:'提取次数',field:'extraction_time',align:'center',width:40},
            
/*            {title:'所处层级',field:'is_leader',align:'center',width:40},


            },*/

            {title:'最后一次提取日期',field:'last_extraction_data',align:'center',width:60},
            
            {title:'最后一次提取金额',field:'last_extraction_bonus',align:'center',width:60},

            {title:'是否已经提取',field:'ifclear',align:'center',width:40,
            	formatter:function(value,rec){
            		return value ==  '1' ? '等待提取' : '已提取';
    			    }	
            }/*, 
//            {title:'生效时间',field:'effect_time',align:'center',width:80},
//
//            {title:'失效时间',field:'expire_time',align:'center',width:80},

/*			{title:'操作',field:'operation',align:'center',width:40,
	        	formatter:function(value,rec){
         		var s = '<a style="cursor:pointer; color:blue" onclick=\'showInfo("' + rec.key + '")\'>查看明细</a>';
	        	    return s;
		   		}
		    }*/
        ]],
		singleSelect: false
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
/*	$('#addBtn').click(addOperation);
	$('#editBtn').click(editOperation);*/
/*	$('#deleteBtn').click(deleteOperation);*/
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
//	alert('2222');
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		/*url: 'A_USR!queryList.do',*/
		url: 'A_ORG_BONUS!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//选择机构
function select_a_org() {
	var action = "A_ORG!showTree.do?model.org_status=01";
	var row = showModalWin(action);
	
	if (row) {
		$('#org_name').val(row.attributes.org_name);
		$('#org_sequence').val(row.attributes.org_sequence);
	}
	
}
//查看明细
function showInfo(key) {
	var url = 'A_USR!showInfo.do?model.key=' + key;
	openWin(url,'pop'); 
}

//添加用户信息表
function addOperation(){  
	var url = 'A_ORG!showAdd1.do';
	openWin(url,'pop');
}

//编辑用户信息表
function editOperation(){  
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}
	
	if (rows[0].usr_status == '03') {
		showInfoWin('已删除的用户不允许修改操作！');
      	return; 
	}

	var url = 'A_ORG!showEdit2.do?model.key=' + rows[0].key;
	openWin(url,'pop');
}   

//删除用户信息表
function deleteOperation() {
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中要删除的记录!');	
		return;
	}

	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}
	var params = $ .param({'id' : ids}, true);

	$ .messager.confirm('提示信息', '您确定要删除选定的' + rows.length + '条记录吗?', function(result){
		if(result){
			$ .ajax({
				url: 'A_USR!doDelete.do',
				data: params,
				type: 'post',
				success: function(data){
				    showInfoWin('操作成功!');
					afterOK();
				}
			});
		}	
	});
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}